/*
 * @info 该文件来自windaeam。
 */
function __ON_IMG_ERROR(e) {
	if (/\.(png|jpg|jpeg|bmp|gif)$/i.test(e.src)) {
		
	} else {
		e.dataset.src = e.src;
		e.src = "page/back/reportingFaults/icon-video.jpg";
	}
}

function __REAL_SRC(e) {
	var src = $(e).attr("src");
	if (src.endsWith('icon-video.jpg')) {
		return e.dataset.src;
	}
	return src;
}

$(".file-name-container-left.form-control .fh-img .box2-img").click(function () {
	console.log("page/back/device/js/img.js 0");
	
	function changeItem(src1) {
		console.log("Adapter preview.");
		
		if (/\.(png|jpg|jpeg|bmp|gif)$/i.test(src1)) {
			$(".enlarge-del").next("img,video").remove();
			$(".enlarge-del").after("<img src='" + src1 + "'/>");
		} else {
			$(".enlarge-del").next("img,video").remove();
			$(".enlarge-del").after("<video controls='controls' src='" + src1 + "'></video>");
		}
	}
	
	$(".enlarge").addClass("enlarge-img");
	var src = __REAL_SRC($(this).find(".img2")[0]);
	$(".enlarge-img").append("<div class='enlarge-left'><</div>");
	$(".enlarge-img").append("<div class='enlarge-right'>></div>");
	$(".enlarge-img").append("<div class='enlarge-del'>×</div>");
	changeItem(src);
	var length = $(".file-name-container-left.form-control .fh-img").length;
	if (length == 1) {
		$(".enlarge-left").css("color", "#555");
		$(".enlarge-right").css("color", "#555");
	}
	var index = $(this).parents(".fh-img").index();
	$("body").on("click", ".enlarge-img .enlarge-left", function () {
		index--;
		if (index < 0) {
			index = length - 1;
		}
		var src1 = __REAL_SRC($(".file-name-container-left.form-control .fh-img:eq(" + index + ") .box2-img .img2")[0]);
		changeItem(src1);
	});
	$("body").on("click", ".enlarge-img .enlarge-right", function () {
		index++;
		if (index == length) {
			index = 0;
		}
		var src1 = __REAL_SRC($(".file-name-container-left.form-control .fh-img:eq(" + index + ") .box2-img .img2")[0]);
		changeItem(src1);
	});
});

$("body").on("click", ".enlarge-img .enlarge-del", function () {
	console.log("page/back/device/js/img.js");
	$(".enlarge-img").empty();
	$(".enlarge").removeClass("enlarge-img");
	
});